<?php

define('NAUTHENTICATE_STATUS_SUCCESS',1);
define('NAUTHENTICATE_STATUS_CANCEL',2);
define('NAUTHENTICATE_STATUS_FAILURE',4);

class NAuthentication {


function __construct(){}
function & getInstance()
	{
		static $instances;

		if (!isset ($instances)) {
			$instances = array ();
		}

		if (empty ($instances[0])) {
			$instances[0] = new NAuthentication();
		}

		return $instances[0];
	}

function authenticate($credentials)
	{
		// Initialize variables
		$auth = false;

		
		// Create authencication response
		$response = new NAuthenticationResponse();

		
		require_once ROOT_DIR."/plugins/authentication/neo.php";
		$plugin = new plgAuthenticationNeo();
// Try to authenticate
			$plugin->onAuthenticate($credentials, $response);

			// If authentication is successfull break out of the loop
			if($response->status === NAUTHENTICATE_STATUS_SUCCESS)
			{
				if (empty( $response->type )) {
					$response->type = isset( $plugin->_name ) ? $plugin->_name : $plugin->name;
				}
   				if (empty( $response->username )) {
					$response->username = $credentials['username'];
				}

				if (empty( $response->fullname )) {
					$response->fullname = $credentials['username'];
				}

				if (empty( $response->password )) {
					$response->password = $credentials['password'];
				}

			}		
		
		return $response;
	}


}

class NAuthenticationResponse{

function __construct(){}
}
?>
